package com.qf.iprate.config;

import com.qf.iprate.filter.BlackListFilter;
import com.qf.iprate.filter.IpRateLimitFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterConfig {

    @Bean
    public FilterRegistrationBean<IpRateLimitFilter> ipRateLimitFilterFilterRegistrationBean(IpRateLimitFilter ipRateLimitFilter){
        FilterRegistrationBean<IpRateLimitFilter> registrationBean = new FilterRegistrationBean<>();

        registrationBean.setFilter(ipRateLimitFilter);
        registrationBean.addUrlPatterns("/*"); // 该过滤器要处理的url路径在这里配置

        registrationBean.setOrder(2);// 设置过滤器的顺序，越小越靠前

        return registrationBean;
    }


    @Bean
    public FilterRegistrationBean<BlackListFilter> blackListFilterFilterRegistrationBean(BlackListFilter blackListFilter){

        FilterRegistrationBean<BlackListFilter> registrationBean = new FilterRegistrationBean<>();

        registrationBean.setFilter(blackListFilter);
        registrationBean.addUrlPatterns("/*"); // 该过滤器要处理的url路径在这里配置

        registrationBean.setOrder(Integer.MIN_VALUE);// 设置过滤器的顺序，越小越靠前

        return registrationBean;

    }




}
